<template>
  <!-- 放置一个图标 -->
  <div style="display:inline-block">
    <svg-icon :icon-class="isFull ? 'exit-fullscreen' : 'fullscreen'" class="fullscreen" @click="toggleFull" />
  </div>
</template>

<script>
import screenfull from 'screenfull'
export default {
  name: 'ScreenFull',
  data() {
    return {
      isFull: false
    }
  },
  created() {
    // 页面一打开, 就绑定事件, 屏幕改变状态的事件 change
    screenfull.on('change', () => {
      console.log('当前是否全屏', screenfull.isFullscreen)
      this.isFull = screenfull.isFullscreen
    })
  },
  methods: {
    toggleFull() {
      screenfull.toggle() // 实现全屏和非全屏的切换
    }
  }
}
</script>

<style lang="scss" scoped>
.fullscreen {
  width: 20px;
  height: 20px;
  color: #fff;
  cursor: pointer;
}
</style>
